SorensenDice

Implements the Sørensen-Dice coefficient, also known as Sørensen index (Sørensen, 1948), Dice's coefficient, or Czekanowski's binary (non-quantitative) index between strings.

The strings are first converted to boolean sets of k-shingles (sequences of k characters), then the similarity is computed as \(\frac{2 \times \lVert V_1 \cap V_2 \rVert}{\lVert V_1 \rVert + \lVert V_2 \rVert}\)

Similar to Jaccard index, but this time the similarity is computed as 2 * |V1 inter V2| / (|V1| + |V2|). Distance is computed as 1 - cosine similarity.

The distance is computed as \(1 - similarity(X, Y)\).

References

Sørensen, T. J. (1948). A method of establishing group of equal amplitude in plant sociobiology based on similarity of species content and its application to analyses of the vegetation on danish commons. Kongelige Danske Videnskabernes Selskab.

Author

Thibault Debatty, solonovamax

Constructors

Link copied to clipboard
constructor(k: Int = DEFAULT_K)

Properties

Link copied to clipboard
val k: Int

Functions

Link copied to clipboard
open override fun distance(s1: String, s2: String): Double

Computes the Sørensen-Dice distance of two strings.

fun distance(profile1: Map<String, Int>, profile2: Map<String, Int>): Double

Computes the Sørensen-Dice distance of precomputed profiles.

Link copied to clipboard
fun profile(string: String): Map<String, Int>

Compute and return the profile of s, as defined by Ukkonen (Ukkonen 1992). The profile is the number of occurrences of k-shingles, and is used to compute q-gram similarity, Jaccard index, etc. Pay attention: the memory requirement of the profile can be up to \(k \times \text{size of the string}\)

Link copied to clipboard
open override fun similarity(s1: String, s2: String): Double

Computes the Sørensen-Dice similarity of two strings.

fun similarity(profile1: Map<String, Int>, profile2: Map<String, Int>): Double

Computes the Sørensen-Dice similarity of precomputed profiles.